﻿using Microsoft.AspNetCore.Mvc;
using mozhi.smarterp.Business.Enums;
using mozhi.smarterp.Business.Sales.Orders;
using System;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Application.Dtos;

namespace mozhi.smarterp.Business.Controllers.Sales
{
    [RemoteService]
    [Route("api/v1/sales/orders")]
    public class SaleOrderController : BusinessController
    {
        private ISaleOrderAppService _appService;

        public SaleOrderController(ISaleOrderAppService appService)
        {
            _appService = appService;
        }

        [HttpGet]
        [Route("{id}")]
        public async Task<SaleOrderDto> GetAsync(Guid id)
        {
            return await _appService.GetAsync(id);
        }

        [HttpGet]
        public async Task<PagedResultDto<SaleOrderDto>> GetAsync(SaleOrderPagedResultRequestDto filter)
        {
            return await _appService.GetListAsync(filter);
        }

        [HttpPost]
        public async Task<SaleOrderDto> CreateAsync(SaleOrderCreateDto input)
        {
            return await _appService.CreateAsync(input);
        }

        [HttpPut]
        public async Task<SaleOrderDto> UpdateAsync(SaleOrderUpdateDto input)
        {
            return await _appService.UpdateAsync(input);
        }

        [HttpPut]
        [Route("{id}/status/{status}")]
        public async Task<SaleOrderDto> UpdateStatusAsync(Guid id, DocumentStatusType status)
        {
            return await _appService.UpdateStatusAsync(id, status);
        }

        [HttpDelete]
        [Route("{id}")]
        public async Task DeleteAsync(Guid id)
        {
            await _appService.DeleteAsync(id);
        }

        [HttpPost]
        [Route("{id}/advance-receipts")]
        public async Task<Guid> PushOrderAsync(Guid id)
        {
            return await _appService.PushAdvanceReceiptAsync(id);
        }

        [HttpPost]
        [Route("{id}/deliveries")]
        public async Task<Guid> PushDeliveryAsync(Guid id)
        {
            return await _appService.PushSaleDeliveryAsync(id);
        }
    }
}
